function [IA_Relation] = IA_Relation_Constraints(IA_Relation1, IA_Relation2, IA_Relation3)
%IA_Relation_Constraints Constraints(R1, R2)
%   Constraints function as per James F. Allen's Interval Algebra (1983)

persistent Transitivity_Matrix;

if isempty(Transitivity_Matrix)
  Transitivity_Matrix = IA_Relation_Transitivity();
end

% C = e
IA_Relation = IA_Relation_Null();

% For each r1 in R1
for a = 1:2
  for b = 1:7
    if (IA_Relation1.set(a, b) > 0)
      % For each r2 in R2
      for c = 1:2
        for d = 1:7
          if (IA_Relation2.set(c, d) > 0)
            % C = C U T(r1, r2);
            IA_Relation_New_Info = Transitivity_Matrix(2 * (a - 1) + c, 7 * (b - 1) + d);
            IA_Relation = IA_Relation_Union(IA_Relation, IA_Relation_New_Info);
            if IA_Relation_Is_Dummy(IA_Relation)
            %if IA_Relation_Is_Equal(IA_Relation3, IA_Relation_Intersect(IA_Relation3, IA_Relation))
              return;
            end
          end
        end
      end
    end
  end
end
end